<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        canvas {
            border: 1px solid red;
        }
    </style>
</head>

<body>
    <canvas width="800" height="600"></canvas>
    <script>
        window.onload = function () {
            //1:获取canvas对象
            let c = document.querySelector('canvas');
            //2：创建实例
            let ctx = c.getContext('2d');
            let rgt = ctx.createRadialGradient(150,150,50,150,150,100);
            rgt.addColorStop(0,'red')
            rgt.addColorStop(1,'green')
            ctx.fillStyle = rgt;
            ctx.moveTo(100,100)
            ctx.lineTo(100,300)
            ctx.lineTo(300,300)
            ctx.lineTo(300,100);
            ctx.closePath()
            ctx.fill()

        }
    </script>
</body>

</html>